package com.sa.app.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sa.app.R;
import com.sa.app.activities.MainActivity;

public class StatsFragment extends Fragment {
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v=inflater.inflate(R.layout.stats_view, null);
		initializeUI(v);
		if(((ViewGroup) v.getParent())!=null){
		((ViewGroup) v.getParent()).removeView(v);
		}
			return v; 
		
	}
	
	public void initializeUI(View v){
		MainActivity act=(MainActivity) getActivity();
		
		//MostUsed
		TextView mostUsed = (TextView) v.findViewById(R.id.mostUsedValue);
		String str=act.getDataBaseManager().getMostUsed();
		mostUsed.setText(str);
		
		//lessUsed
		TextView lessUsed = (TextView) v.findViewById(R.id.lessUsedValue);
		str=act.getDataBaseManager().getLessUsed();
		lessUsed.setText(str);
		
		//numItems
		TextView numItems = (TextView) v.findViewById(R.id.numItemsValue);
		Integer num=act.getDataBaseManager().getNumItems();
		numItems.setText(String.valueOf(num));
		
		//timesTagged
		TextView timesTagged = (TextView) v.findViewById(R.id.timesTaggedValue);
		num=act.getDataBaseManager().getNumTimesTagged();
		timesTagged.setText(String.valueOf(num));
		
		//servicesUsed
		TextView servicesUsed = (TextView) v.findViewById(R.id.servicesUsedValue);
		num=act.getDataBaseManager().getNumServicesUsed();
		servicesUsed.setText(String.valueOf(num));
	}
	//Esto hace que no cuelgue la aplicación al cambiar de activity utilizando la libreria de compatibilidad
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        setUserVisibleHint(true);
    }
}